import requests
from flask import Flask, request, Response, render_template

app = Flask(__name__, template_folder='templates')


@app.route('/log')
def show_log():
    file_uri = request.args.get('fileuri')
    if not file_uri:
        return 'fileuri is required', 400
    try:
        res = requests.get(file_uri)
        file_content = res.content.decode('utf-8')
    except Exception as e:
        return f'Error: {e}', 500

    return Response(
        render_template('log.html', file_content=file_content),
        content_type='text/html; charset=utf-8')


@app.route('/render')
def render_log():
    return render_template('render-log.html')


if __name__ == '__main__':
    app.run(debug=False, host='0.0.0.0', port=5000)
